// 流程管理接口
import { ajaxService } from '@/utils/request';
import { Flow, FlowParams } from './type';

const env = import.meta.env;
const baseURL = env.VITE_APP_BASE_URL;
/**
 *
 * @param data 新增流程
 * @returns
 */
export async function AddFlow(data: Flow) {
  return ajaxService<{ processId?: number }>({
    url: '/flow/process',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 获取流程列表
 * @param params
 * @returns
 */
export async function getFlowList(params: FlowParams) {
  return ajaxService<{ processList?: any }>({
    url: '/flow/process/page',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 获取所有流程
 * @returns
 */
export async function getFlowAll() {
  return ajaxService<any>({
    url: '/platform_ccc/Flow/all',
    method: 'get',
    baseURL
  });
}
export async function getFlowById(id: number) {
  return ajaxService<any>({
    url: `/flow/process/${id}`,
    method: 'get',
    baseURL
  });
}
/**
 * 编辑流程
 * @param params
 * @returns
 */
export async function editFlow(data: FlowParams) {
  return ajaxService<{ processId?: number }>({
    url: '/flow/process',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 发布流程
 * @param params
 * @returns
 */
export async function releaseFlow(data: { id: number }) {
  return ajaxService<any>({
    url: '/flow/release/process',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 删除流程
 * @param params
 * @returns
 */
export async function delFlowByIds(data: { ids: number[] }) {
  return ajaxService({
    url: `/flow/process`,
    method: 'delete',
    baseURL,
    data
  });
}
/**
 * 流程查重
 */
export async function flowDuplicateCheck(params: { flowName: string }) {
  return ajaxService<any>({
    url: `/flow/process/duplicate/check`,
    method: 'get',
    baseURL,
    params
  });
}
